package com.xinxin.blockchain.api.config;

import com.xinxin.base.configure.AppWebConfigurerSupport;
import com.xinxin.base.holder.ThreadLocalContextHolder;
import com.xinxin.blockchain.api.interceptor.AuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

@Configuration
public class AppWebConfigurer extends AppWebConfigurerSupport {

    @Bean
    public ThreadLocalContextHolder<Long> userContextHolder() {
        return new ThreadLocalContextHolder<>();
    }

    @Bean
    public AuthInterceptor authInterceptor() {
        return new AuthInterceptor(userContextHolder());
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);

        registry.addInterceptor(authInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_PATH_PATTERNS)
                .excludePathPatterns("/common/**")
                .excludePathPatterns("/member/login/**")
        ;
    }
}
